package com.example.myapplication;

import android.util.Log;

import com.example.myapplication.bean.BaseBean;
import com.example.myapplication.bean.Weather15DayBean;
import com.example.myapplication.bean.WeatherBean;
import com.example.myapplication.untils.HttpUtils;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

public class Test {

    public static void main(String[] args) {
        HttpUtils httpUtils = new HttpUtils();
        try {

            HashMap<String, String> map = new HashMap<>();
            map.put("Authorization", "APPCODE bc70323d41644bad991822fe3748476c");
            String s = httpUtils.postJson("http://aliv8.data.moji.com/whapi/json/aliweather/forecast15days?lat=39.91488908&lon=116.40387397", map, null);
            JSONObject jsonObject = JSONUtil.parseObj(s);
            Object data = jsonObject.getByPath("data.forecast");
            Gson gson = new Gson();

            String json = gson.toJson(data);

            JsonParser parser = new JsonParser();
            JsonArray jsonArray = parser.parse(json).getAsJsonArray();
            ArrayList<Weather15DayBean> list = new ArrayList<>();
            for (JsonElement jsonElement : jsonArray) {
                Weather15DayBean weather15DayBean = gson.fromJson(jsonElement, Weather15DayBean.class);
                list.add(weather15DayBean);
            }
            list.subList(0, 2).clear();
            list.subList(3, list.size()).clear();

            System.out.println(list);

        } catch (IOException e) {
            Log.e("陈景涛", "e: ",e );
            throw new RuntimeException(e);
        }
    }



}
